import io._;
import scala.util.DynamicVariable
import java.nio.file._
import java.io.File

class IO {

}
object IO{
 // var IOPeer peer=null
  var maxAnswers=0
  var showOutput=true;
  var showErrors=true;  
  val showTrace=0;
  var input=Source.stdin
  private val outVar = new DynamicVariable[PrintStream](java.lang.System.out)
   def out = outVar.value

  
  def toFileReader(s: String) : String ={
    return Source.fromFile(s,"UTF-8").toString
  }
  
   def toUrlReader(s: String) : String ={
    return Source.fromURL(s,"UTF-8").toString
  }

   def toFileWriter(s:String): Writer ={
     val out = new PrintWriter(s)
   }
  
  def getStdInput() : Reader={
    return input
  }
  
  def getStdOutput(): Writer={
    return out
  }
  
 def print(obj: Any) {
 out.print(if (null == obj) "null" else obj.toString())
  }
 
 // stream
  def print() { print(", ") }

  def print(sep: String) {
  def loop(these: Stream[A], start: String) {
	      Console.print(start)
	      if (these.isEmpty) Console.print("empty")
	      else { 
	        Console.print(these.head)
	        loop(these.tail, sep) 
	      }
	    }
	    loop(this, "")
	  }


 
   def println() { out.println() }

   def println(x: Any) { out.println(x) }

   def readln(): String = in.readLine()
   
   def readln(text: String, args: Any*): String = {
	    printf(text, args: _*)
	    readLine()
	  }

   	def promptln(p:String) : String ={
   	  print(p)
   	  return readln
   	}
   
   	def mes(s:String): Unit ={
   	  println(s)
   	}
   	
   	def trace(): String = thrownException.getStackTraceString
   	lazy val traceSourcePath  = str("scala.control.sourcepath", "sourcepath for looking up stack trace elements")
  
   	def errmes(s:String) : Unit={
   	  if(showErrors)
   	  {
   	    println(s)
   	  }
   	}
   	
   	def errmes(s:String, Throwable e):Unit={
   	  errmes(s)
   	  println(traceSourcePath)
   	}
   	
   	
   	implicit def makeFileVisitor(f: (Path) => Unit) = new SimpleFileVisitor[T] {
   		override def visitFile(p: Path, attrs: attribute.BasicFileAttributes) = {
   			f(p)
   			FileVisitResult.CONTINUE
   		}
   	}
   	//Files.walkFileTree(dir.toPath, (f: Path) => println(f)println(f))

   	
   	def subdirs(dir: File): Iterator[File] = {
   			val children = dir.listFiles.filter(_.isDirectory)
   			children.toIterator ++ children.toIterator.flatMap(subdirs _)
   	}
   	//for (d <- subdirs(dir)) process d
   	
  

}
